<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>通知详情-云校通</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<body ontouchstart id="xs_c">
	<div class="weui_tab tab-bottom">
		<div class="weui-header bg-blue"> 
	  		<div class="weui-header-left"><a onclick="back()" href="javascript:;" class="icon icon-109 f-white">返回</a></div>
	    	<h1 class="weui-header-title">${notice.noticeTypeText }</h1>
		</div>
		<div class="weui_tab_bd">
			<div class="weui-weixin">
				<div class="weui-weixin-ui">
				   <div class="weui-weixin-page pt10">
					   <div class="weui-weixin-info">
	                     <span class="weui-weixin-em">发布时间：</span>
	                      <em class="weui-weixin-em" ><fmt:formatDate value="${notice.createTime}" type="time" timeStyle="short"/></em>
	                    </div>
					</div>
				  </div>
				</div>
				<div class="weui_cells xs_c_content">
				    <div class="weui-weixin-content">
	                    <p>${notice.content }</p>
	                </div>
				</div>
				<div class="weui_cells xs_c_piclist">
	                <div class="xs_c_picWrap clearfix">
	                	<c:forEach var="item" items="${notice.attachList }">
	                		<c:if test="${item.attachmentType == 'image' }">
	                			<div class="xs_c_pic" onclick="imgClick1(this)"><img src="${config.imgUrl }${item.attachmentUrl}"></div>
	                		</c:if>
	                	</c:forEach>
	                </div>
				</div>
				
				<div class="weui_cells xs_c_piclist p5">
	                <div class="xs_c_picWrap clearfix">
						<c:forEach var="item" items="${notice.attachList }">
							<c:if test="${item.attachmentType != 'image' }">
								<div class="xtbg-upload-list mb10">
									<div class="xtbg-upload-list-inner">
										<p>${item.attachmentName}</p>
										<a href="${config.imgUrl}${item.attachmentUrl}" class="weui_btn weui_btn_mini weui_btn_primary f-white bg-blue">查看</a>
									</div> 
								</div>
							</c:if>
						</c:forEach>
					</div>
				</div>
				
				<div class="weui_cells mb50">
					<div class="weui_cell">发布人：
						<c:choose>
							<c:when test="${notice.noticeType == 4 }">
								石门实验中学附属小学
							</c:when>
							<c:otherwise>
								${notice.sender } 老师
							</c:otherwise>
						</c:choose>
					</div>
				</div>
				<!--查看状态-->
				<c:if test="${sendeeId == notice.senderId }">
					<div class="page-bd xs_c_search">
						<ul>
							<li class="xs_c_search-first">
				                <div class="weui-flex js-category">
				                    <p class="weui-flex-item"><img class="middle" src="<%=basePath%>/images/weichakan.png"/> 未查看（<span id="noReadCount"></span>）</p>
				                    <button class="weui_btn bg-blue weui_btn_mini" id="resetSend" style="margin-right: 20px;"> 重发 </button> 
				                    <i class="icon icon-74"></i>
				                </div>
				                <div class="page-category js-categoryInner">
				                    <ul class="list_5" id="noRead">
				                    </ul>
				                </div>
				            </li>
				            <li class="">
				                <div class="weui-flex js-category">
				                    <p class="weui-flex-item"><img class="middle" src="<%=basePath%>/images/yichakan.png"/> 已查看（<span id="readedCount"></span>）</p>
				                    <i class="icon icon-74"></i>
				                </div>
				                <div class="page-category js-categoryInner">
				                    <ul class="list_5" id="readed">
				                    </ul>
				                </div>
				            </li>
						</ul>
					</div>
				</c:if>
				<!--End查看状态-->
			<div class="mb55"></div>
		</div>
	</div>
</body>
<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
<script type="text/javascript">
	var sendeeId = parseInt("${sendeeId}");
	var noticeId = parseInt("${notice.id}");
	var senderId = parseInt("${notice.senderId}");
	var isRead = parseInt("${notice.isRead}");
	$(function() {
		$('.js-category').click(function(){
			$parent = $(this).parent('li');
		    if($parent.hasClass('js-show')){
                $parent.removeClass('js-show');
                $(this).children('i').removeClass('icon-35').addClass('icon-74');
            }else{
                $parent.siblings().removeClass('js-show');
                $parent.addClass('js-show');
                $(this).children('i').removeClass('icon-74').addClass('icon-35');
                $parent.siblings().find('i').removeClass('icon-35').addClass('icon-74');
            }
	   });
	   $("#resetSend").click(function() {
		   $.confirm("您确定要重发吗?", "确认重发?", function() {
			   repeatNotice()
	       }, function() {
	          //取消操作
	       });
	   })
	   if(sendeeId == senderId) readList();
	   if(isRead == 0) readUpdate();
	})
	function repeatNotice() {
		$.ajax({
          	url : basePath + "/ls/notice/repeat",
  	 		type : "post",
  	 		dataType : "json",
  	 		data : {
  	 			noticeId: noticeId
  	 		},
            success: function(data){
            	if(data.code == '000') $.toast("操作成功");
            	else $.toast(data.msg, "cancel");
            },
            error: function(xhr, type){
                  
            }
          });
	}
	function readUpdate() {
		var noticeIds = new Array();
		noticeIds.push(noticeId);
		$.ajax({
          	url : basePath + "/notice/read/modify",
  	 		type : "post",
  	 		dataType : "json",
  	 		data : {
  	 			sendeeId: sendeeId,
  	 			noticeIds: noticeIds
  	 		},
            success: function(data){
            },
            error: function(xhr, type){
                  
            }
          });
	}
	function readList() {
		var sendeeType = parseInt("${notice.sendeeType}");
		$.ajax({
          	url : basePath + "/notice/read/list",
  	 		type : "post",
  	 		dataType : "json",
  	 		data : {
  	 			noticeId: noticeId,
  	 			sendeeType: sendeeType
  	 		},
            success: function(data){
            	if(data != null && data.length > 0) {
            		var noReadHtml="", noReadCount=0, readedHtml="", readedCount=0;
            		for(var i in data) {
            			var itm = data[i];
            			var str = "<li>" + itm.sendee + (sendeeType == 1 ? "家长" : "") + "</li>";
            			if(itm.isRead > 0) {
            				readedCount++;
            				readedHtml += str;
            			}else {
            				noReadCount++;
            				noReadHtml += str;
            			}
            		}
            		$("#noRead").html(noReadHtml);
            		$("#noReadCount").html(noReadCount);
            		$("#readed").html(readedHtml);
            		$("#readedCount").html(readedCount);
            	}
            },
            error: function(xhr, type){
                  
            }
          });
	}
	function imgClick1(thiz) {
		var obj = $(thiz.closest(".xs_c_picWrap")).find("img");
		var src = get_img(obj);
		var currSrc = thiz.children[0].src;
		var current;
		for(var i in src) {
			if(src[i] == currSrc) {
				current = i;
				break;
			}
		}
		img_preview(src[current], src);
	}
	function img_preview(current, urls){
	    if(!current || urls.length == 0){
	        return ;
	    }
	
	    WeixinJSBridge.invoke('imagePreview', { 
	        'current': current,
	        'urls': urls
	    }); 
	}
	function get_img(obj){
		var m = [];
		for(var i=0; i<obj.length; i++){
			m[i] = obj[i].src;
		}
		return m;
	}
</script>
</html>